package de.hauck.rtmidlet.views;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import de.hauck.rtmidlet.RTMidlet;
import de.hauck.rtmidlet.model.Configuration;
import de.hauck.rtmidlet.utils.MyLogger;

public class FormLinks extends Form implements CommandListener {
	private Configuration c;
	private Display _display;
	private RTMidlet _main;
	private FormSettingsMenu _fm;
	private Command cSave = new Command("Save", Command.OK, 1);
	private Command cCancel = new Command("Cancel", Command.BACK, 1);
	private TextField url1, url2, url3,url4, link1, link2;
	//private TextField
	
	public FormLinks(RTMidlet rtmidlet, FormSettingsMenu fm) {
		super("Link Settings");
		_main=rtmidlet;
		_fm=fm;
		
		url1=new TextField("URL RT", c.urlRT, 255, 0);
		url2=new TextField("URL TS", c.urlTS, 255, 0);
		url3=new TextField("URL INTRADAY", c.urlINTRADAY, 255, 0);
		url4=new TextField("URL FT", c.urlFINANZTREFF, 255, 0);
		link1=new TextField("Link FT", c.linkFT, 255, 0);
		link2=new TextField("Link OV", c.linkOV, 255, 0);
		append(url1);
		append(url2);
		append(url3);
		append(url4);
		append(link1);
		append(link2);
		
		addCommand(cSave);
		addCommand(cCancel);
		setCommandListener(this);
		_main.show(this);		
	}

	public void commandAction(Command command, Displayable dble) {
		if (command==cSave) {
			Configuration.dirtyFlagConfig=true;
			MyLogger.debug("Setting Link settings");
			c.urlRT=url1.getString();
			c.urlTS=url2.getString();
			c.urlINTRADAY=url3.getString();
			c.urlFINANZTREFF=url4.getString();
			c.linkFT=link1.getString();
			c.linkOV=link2.getString();		
			_main.show(_fm.getSettingsMenu());
		} else if (command == cCancel) {
			_main.show(_fm.getSettingsMenu());
		}
		
	}

}
